/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.asiainfo.utils.sql.sqlbuilder.select;

import java.sql.SQLException;
import java.util.List;

public class Where implements TerminalExpression {
	private Context context;

	public Where(Context context) {
		this.context = context;
		context.append("WHERE");
		context.append("1 = 1");
	}

	public OrderBy orderBy() {
		return new OrderBy(this.context);
	}

	public Where and(Object condition) {
		new AndCondition(this.context).add(condition);
		return this;
	}

	public Where and(Object condition, Object parameter) {
		new AndCondition(this.context).add(condition, parameter);
		return this;
	}

	public Where and(String condition, String parameter) {
		new AndCondition(this.context).add(condition, parameter);
		return this;
	}

	public Where and(Object condition, Object[] parameters) {
		new AndCondition(this.context).add(condition, parameters);
		return this;
	}

	public Where andBetween(String columnName, Object start, Object end) {
		new AndCondition(this.context).between(columnName, start, end);
		return this;
	}

	public Where andIn(String columnName, Object[] objects) {
		new AndCondition(this.context).in(columnName, objects);
		return this;
	}

	public Where andIn(String condition, String parameter) {
		new AndCondition(this.context).in(condition, new Object[]{parameter});
		return this;
	}

	public Where andIn(Object condition, Object[] parameters) {
		new AndCondition(this.context).in(condition, parameters);
		return this;
	}

	public Where or(Object condition) {
		new OrCondition(this.context).add(condition);
		return this;
	}

	public Where or(Object condition, Object parameter) {
		new OrCondition(this.context).add(condition, parameter);
		return this;
	}

	public Where or(String condition, String parameter) {
		new OrCondition(this.context).add(condition, parameter);
		return this;
	}

	public Where or(Object condition, Object[] parameters) {
		new OrCondition(this.context).add(condition, parameters);
		return this;
	}

	public Where orBetween(String columnName, Object start, Object end) {
		new OrCondition(this.context).between(columnName, start, end);
		return this;
	}

	public Where orIn(String columnName, Object[] objects) {
		new OrCondition(this.context).in(columnName, objects);
		return this;
	}

	public Limit limit(int start, int size) {
		return new Limit(this.context, start, size);
	}

	public <E> List<E> list(RowMapper<E> rowMapper) throws SQLException {
		return this.context.list(rowMapper);
	}

	public <E> E single(RowMapper<E> rowMapper) throws SQLException {
		return this.context.single(rowMapper);
	}
}